﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

/// <summary>
/// Summary description for KeyFigure
/// </summary>
public class KeyFigure
{
  private const string SP = "KeyFigures_GetById";
  DatabaseManager db;
  MySqlDataReader reader;

  public string Id { get; set;  }
  public int Year { get; set; }
  public double GrossMarginRatio { get; set; }
  public double OperatingMargin { get; set; }
  public double ROI { get; set; }
  public double ReturnOnEquity { get; set; }
  public double EquityRatio { get; set; }
  public double DegreeOfliquidity { get; set; }

  public KeyFigure()
  {
    db = new DatabaseManager();
  }

  public void Load(string id, int year)
  {
    db.AddParameter("@id", id);
    db.AddParameter("@year", year);
    using (reader = db.ExecuteStoredProcedure(SP))
    {
      while (reader.Read())
      {
        Id = reader["id"].ToString();
        Year = Convert.ToInt32(reader["year"].ToString());
        GrossMarginRatio = Convert.ToDouble(reader["gross_margin_ratio"].ToString());
        OperatingMargin = Convert.ToDouble(reader["operation_margin"].ToString());
        ROI = Convert.ToDouble(reader["roi"].ToString());
        ReturnOnEquity = Convert.ToDouble(reader["return_on_equity"].ToString());
        EquityRatio = Convert.ToDouble(reader["equity_ratio"].ToString());
        DegreeOfliquidity = Convert.ToDouble(reader["degree_of_liquidity"].ToString());
      }
    }
  }
}